<?php
/*      Database Component      */
require_once 'api.core.php';

class EAPIDatabase extends EAPICore {

	protected       $apicore;
	private         $link;

	public function EAPIDatabase(){

		try{
			
			$settings = EAPICore::getSettings();
	
			$this->apicore = array("__APISite" => $settings['eveApiSite'],
									"__APITime" => $settings['eveApiTime'],
									"__APIDebug" => $settings['eveApiDebug']);
			
			if(empty($this->apicore) || empty($settings)){
				
				throw new EAPIException('Cannot Initiate EAPI Core',601.1);
				
			}
	
			/*      Get database settings   */
			$db		= $settings['dbname'];
			$host   = $settings['dbhost'];
			$user   = $settings['dbusername'];
			$pass   = $settings['dbpassword'];
	
			/*      Establish a connection to the database  */
			$this->link = mysql_connect($host, $user, $pass);

			if(!$this->link){
				throw new EAPIException("Cannot Connect To Database",601.2);
			}
			
			mysql_select_db($db, $this->link);
			register_shutdown_function(array(&$this, 'close'));
		
		}catch (EAPIException $e){
			
			print $e;
			die();
			
		}
		
	}

	function affectedRows(){

		return mysql_affected_rows();

	}

	function query($query){

		return mysql_query($query);

	}

	function fetchArray($result){

		return mysql_fetch_array($result);

	}

	function fetchAssoc($result){

		return mysql_fetch_assoc($result);

	}

	function numRows($result){

		return mysql_num_rows($result);

	}

	function fetchRow($result){

		return mysql_fetch_row($result);

	}

	function close() {

		mysql_close($this->link);

	}
}
?>